package com.intellagric.controller.module.trace_record;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.pojo.TraceRecordSale;
import com.intellagric.service.traceability.trace_record.SalerecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.UUID;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2019/1/13
 * @DESC： 销售记录管理
 */
@Controller
public class SalerecordController {

    @Autowired
    private SalerecordService salerecordService;

    /**
     * 添加销售记录信息
     * @Param recordSale
     * @return ResponseMessage
     */
    @RequestMapping("/record/sale/add")
    @ResponseBody
    public ResponseMessage add(TraceRecordSale recordSale) {
        recordSale.setId(UUID.randomUUID().toString().replaceAll("-",""));
        recordSale.setCreateDate(new Date());
        recordSale.setUpdateDate(new Date());
        return salerecordService.addSalerecord(recordSale);
    }


    /**
     * 删除销售记录信息
     * @Param id
     * @return ResponseMessage
     */
    @RequestMapping("/record/sale/delete")
    @ResponseBody
    public ResponseMessage delete(String id) {
        return salerecordService.deleteISalerecord(id);
    }

    /**
     * 修改销售记录信息
     * @Param
     * @return ResponseMessage
     */
    @RequestMapping("/record/sale/edit")
    @ResponseBody
    public ResponseMessage edit(TraceRecordSale recordSale) {
        recordSale.setUpdateDate(new Date());
        return salerecordService.editSalerecord(recordSale);
    }

    /**
     * 查询销售记录信息
     * @return Object
     */
    @RequestMapping("/record/sale/{id}")
    @ResponseBody
    public Object get(@PathVariable String id) {
        return salerecordService.getSalerecordById(id);
    }

    /**
     * 查询销售记录信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/record/sale/list")
    @ResponseBody
    public LayuiDataGridResult getList() {
        return salerecordService.getSalerecordList();
    }

    /**
     * 分页查询销售记录信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/record/sale/page")
    @ResponseBody
    public LayuiDataGridResult getPage(int page,int limit ) {
        return salerecordService.getSalerecordPage(page, limit);
    }

    /**
     * 分页查询销售记录信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/record/sale/query")
    @ResponseBody
    public LayuiDataGridResult getPageByVo(int page,int limit) {
        return salerecordService.getSalerecordPage(page, limit);
    }

}
